
#auto generate vehicle records for testing
from django.core.management.base import BaseCommand
from vr_app.models import VehicleRecord  # 假设你的车辆记录模型名为VehicleRecord
import random
from datetime import datetime, timedelta
import time
from django.utils import timezone


class Command(BaseCommand):
    help = 'Generates 100 vehicle entry and exit records for demo.'

    def handle(self, *args, **kwargs):
        for _ in range(200):
            vr = VehicleRecord()
            if random.choice([True, False]):
                entry_time = timezone.now() - timedelta(days=random.randint(1, 30))
                vr.payment_status = 'pending'
            else:
                entry_time = timezone.now() - timedelta(days=random.randint(1, 30))
                exit_time = entry_time + timedelta(hours=random.randint(1, 12))
                vr.exit_time = exit_time
                vr.payment_status = 'paid'

            vr.entry_time = entry_time
            vr.license_plate = "{}{}{}".format(
                random.choice("京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼"),
                random.choice("ABCDEFGHIJKLMNO"),
                "".join(random.choices("ABCDEFGHJKLMNPQRSTUVWXYZ0123456789", k=5))
            )
            vr.save()
            time.sleep(0.01)

        self.stdout.write(self.style.SUCCESS('Successfully generated 100 vehicle records.'))
